<!--评价等次明细表-->
<template>
  <el-dialog :title="!dataForm.id ? '新增' : '修改'" :close-on-click-modal="false" :visible.sync="visible" width="800px">
    <el-container>
      <el-main style="max-height:60vh">
        <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="140px">

          <el-row>
            <el-col :span="24" :xs="24">
              <el-form-item label="等次名称" prop="dcName">
                <el-input v-model="dataForm.dcName" placeholder="等次名称" class="kuan"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12" :xs="24">
              <el-form-item label="等次分值" prop="dcFz">
                <el-input-number v-model="dataForm.dcFz" :min="0" :max="10" label="等次分值"></el-input-number>
              </el-form-item>
            </el-col>
            <el-col :span="12" :xs="24">
              <el-form-item label="等次结果起" prop="dcJgq">
                <el-input-number v-model="dataForm.dcJgq" :min="0" :max="10" label="等次结果起"></el-input-number>
              </el-form-item>
            </el-col>
            <el-col :span="12" :xs="24">
              <el-form-item label="等次结果止" prop="dcJgz">
                <el-input-number v-model="dataForm.dcJgz" :min="0" :max="10" label="等次结果止"></el-input-number>
              </el-form-item>
            </el-col>
            <el-col :span="12" :xs="24">
              <el-form-item label="等次排序" prop="dcSort">
                <el-input-number v-model="dataForm.dcSort" :min="0" :max="10" label="等次排序"></el-input-number>
              </el-form-item>
            </el-col>
            <el-col :span="12" :xs="24">
            </el-col>
          </el-row>
        </el-form>
      </el-main>
    </el-container>
    <span slot="footer" class="dialog-footer">
      
      <el-button type="primary" @click="dataFormSubmit()" v-if="canSubmit">确定</el-button>
      <el-button type="primary" plain @click="visible = false">取消</el-button>
    </span>
  </el-dialog>
</template>

<script>
import { getObj, addObj, putObj } from '@/api/ceping/cepingdjmxb'

export default {
  data() {
    return {
      visible: false,
      canSubmit: false,
      dataForm: {
        id: 0,
        djId: '',
        dcName: '',
        dcFz: '',
        dcJgq: '',
        dcJgz: '',
        dcSort: '',

        createTime: '',
        editTime: '',
        createDeptId: '',
        createDeptName: '',
        createUserId: '',
        createUserName: '',
        editDeptId: '',
        editDeptName: '',
        editUserId: '',
        editUserName: '',
        dataState: '',
        tenantId: ''
      },
      dataRule: {
        djId: [
          { required: true, message: '所属等次不能为空', trigger: 'blur' }
        ],
        dcName: [
          { required: true, message: '排名名称不能为空', trigger: 'blur' },
          { min: 2, max: 30, message: '长度在 2 到 30 个字符', trigger: 'blur' }
        ],
        dcFz: [
          { required: true, message: '等次分值不能为空', trigger: 'blur' },
          // { min:1, max:10, message: '长度在 1 到 10 位', trigger: 'blur' }
        ],
        dcJgq: [
          { required: true, message: '等次结果起不能为空', trigger: 'blur' },
          // { min:1, max:10, message: '长度在 1 到 10 位', trigger: 'blur' }
        ],
        dcJgz: [
          { required: true, message: '等次结果止不能为空', trigger: 'blur' },
          // { min:1, max:10, message: '长度在 1 到 10 位', trigger: 'blur' }
        ],
        dcSort: [
          { required: true, message: '等次排序不能为空', trigger: 'blur' },
          // { min:0, max:10, message: '长度在 1 到 10 位11', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    init(ruleId, id) {
      this.dataForm.id = id || 0;
      this.visible = true;
      this.canSubmit = true;
      this.$nextTick(() => {
        this.$refs['dataForm'].resetFields()
        if (this.dataForm.id) {
          getObj(this.dataForm.id).then(response => {
            this.dataForm = response.data.data
          })
        } else {
          this.dataForm = {};
          if (ruleId) {
            this.$set(this.dataForm, 'djId', ruleId)
          }
        }
      })
    },
    // 表单提交
    dataFormSubmit() {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          this.canSubmit = false;
          if (this.dataForm.id) {
            putObj(this.dataForm).then(data => {
              this.$notify.success('修改成功')
              this.visible = false
              this.$emit('refreshDataList')
              this.$emit('getSubList')
            }).catch(() => {
              this.canSubmit = true;
            });
          } else {
            addObj(this.dataForm).then(data => {
              this.$notify.success('添加成功')
              this.visible = false
              this.$emit('refreshDataList')
              this.$emit('getSubList')
            }).catch(() => {
              this.canSubmit = true;
            });
          }
        }
      })
    }
  }
}
</script>
